package studyandroid.android.study.gophern.studyandroid;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

import java.util.Date;

public class Test1Activity extends Activity {
	boolean False = false;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_test1);

		findViewById(R.id.mnShowDialog).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				new AlertDialog.Builder(Test1Activity.this).setTitle("确认退出吗？")
						.setIcon(android.R.drawable.ic_dialog_alert)
						.setCancelable(false)
						.setPositiveButton("确定", new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog, int which) {
								// 点击“确认”后的操作
								Test1Activity.this.finish();
							}
						})
						.setNegativeButton("返回", new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog, int which) {
								// 点击“返回”后的操作,这里不设置没有任何操作
							}
						}).show();
			}
		});

		findViewById(R.id.mnCustomiseAlertDialog).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				//final FragmentActivity activity = getActivity();
				final Activity activity = Test1Activity.this;

				AlertDialog.Builder builder = new AlertDialog.Builder(activity);
				builder.setMessage("Are you sure?");
				if (False) {
					builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int which) {
							activity.finish();
						}
					});
					builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int which) {
						}
					});
				}

				LayoutInflater inflater = LayoutInflater.from(activity);
//				LayoutInflater inflater = getLayoutInflater();
				View dialoglayout = inflater.inflate(R.layout.customise_alert_dlg, null);
				builder.setView(dialoglayout);
				final AlertDialog dlg = builder.create();
				dialoglayout.findViewById(R.id.button3).setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View v) {
						activity.setTitle((new Date()).toString());
						dlg.dismiss();
					}
				});

				dlg.show();
			}
		});
	}
}
